﻿using MediatR;
using Microsoft.EntityFrameworkCore;
using Traceability.Commont.Domains.BatchManagementFiles;
using Traceability.Commont.DTOs.CommontFiles;
using Traceability.Commont.Infrastructures.Interfaces;
namespace U.Enterprise.Api.Applications.WhitestripWeighing
{
    public class PartitionSearchHandler : IRequestHandler<PartitionSearchCommand, Resqults>
    {
        private readonly IBateRepository<Partition> partitionBate;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="partitionBate"></param>
        public PartitionSearchHandler(IBateRepository<Partition> partitionBate)
        {
            this.partitionBate = partitionBate;
        }
        /// <summary>
        /// 分割领用显示
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<Resqults> Handle(PartitionSearchCommand request, CancellationToken cancellationToken)
        {
            var resqults = new Resqults() { Code = 0 };
            try
            {
                var list = await partitionBate.GetAll().ToListAsync();
                if (list != null)
                {
                    resqults.Code = 1;
                    resqults.Date = list;
                    resqults.Messges = "分割领用显示成功";
                }
            }
            catch (Exception)
            {

                resqults.Messges = "分割领用显示失败";
            }
            return resqults;
        }
    }
}
